package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.TProduct;
import com.ruoyi.system.service.TProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TProduct)表控制层
 *
 * @author makejava
 * @since 2025-01-01 20:37:34
 */
@RestController
@RequestMapping("tProduct")
public class TProductController extends BaseController {

    private String prefix = "system/product";
    /**
     * 服务对象
     */
    @Resource
    private TProductService tProductService;

    @GetMapping()
    public String list()
    {
        return prefix + "/product";
    }
    /**
     * 分页查询
     *
     * @param tProduct 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(TProduct tProduct,
                                     @RequestParam(defaultValue = "0") int page,
                                     @RequestParam(defaultValue = "10") int size,
                                     @RequestParam(required = false) String sortField,
                                     @RequestParam(required = false, defaultValue = "asc") String sortOrder) {
        startPage();
        List<TProduct> result = this.tProductService.queryByPage(tProduct);
        return getDataTable(result);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TProduct> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tProductService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tProduct 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TProduct> add(TProduct tProduct) {
        return ResponseEntity.ok(this.tProductService.insert(tProduct));
    }

    /**
     * 编辑数据
     *
     * @param tProduct 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TProduct> edit(TProduct tProduct) {
        return ResponseEntity.ok(this.tProductService.update(tProduct));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.tProductService.deleteById(id));
    }

}

